import java.util.*;

/**
 * @作者 钟先崟
 * @时间 2023-02-23 15:06
 * @说明 1023. 驼峰式匹配
 * 如果我们可以将小写字母插入模式串 pattern 得到待查询项 query，那么待查询项与给定模式串匹配。（我们可以在任何位置插入每个字符，也可以插入 0 个字符。）
 * 给定待查询列表 queries，和模式串 pattern，返回由布尔值组成的答案列表 answer。只有在待查项 queries[i] 与模式串 pattern 匹配时， answer[i] 才为 true，否则为 false。
 * 示例 1：
 * 输入：queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"
 * 输出：[true,false,true,true,false]
 * 示例：
 * "FooBar" 可以这样生成："F" + "oo" + "B" + "ar"。
 * "FootBall" 可以这样生成："F" + "oot" + "B" + "all".
 * "FrameBuffer" 可以这样生成："F" + "rame" + "B" + "uffer".
 */
public class Solution {
    public static void main(String[] args) {
//        String[] queries = new String[]{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"};
//        String pattern = "FoBa";
//        String[] queries = new String[]{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"};
//        String pattern = "FB";
//        String[] queries = new String[]{"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"};
//        String pattern = "FoBaT";
        String[] queries = new String[]{"CompetitiveProgramming", "CounterPick", "ControlPanel"};
        String pattern = "CooP";
        List<Boolean> booleans = camelMatch(queries, pattern);
        for (boolean b :
                booleans) {
            System.out.print(b + " ");
        }

    }

    public static List<Boolean> camelMatch(String[] queries, String pattern) {
        List<Boolean> booleans = new ArrayList<>();
        List<String> patterns = new ArrayList<>();//把pattern分割成多个字串
        int left = 0;
        int i;
        int len = 0;
        for (i = 1; i < pattern.length(); i++) {
            if (pattern.charAt(i) >= 'A' && pattern.charAt(i) <= 'Z') {//如果遇到大写
                String str = pattern.substring(left, i);
                patterns.add(str);
                left = i;
                len++;
            }
        }
        if (i != 0 && i == pattern.length()) {//补最后一个
            String str = pattern.substring(left, i);
            patterns.add(str);
            len++;
        }

        for (i = 0; i < queries.length; i++) {
            int n = 0;
            left = 0;
            boolean flag = true;
            int j;
            for (j = 1; j < queries[i].length() && n < len; j++) {
                if (queries[i].charAt(j) >= 'A' && queries[i].charAt(j) <= 'Z') {
                    String substring = queries[i].substring(left, j);
                    String s = patterns.get(n);
                    int i1 = substring.indexOf(s);
                    if (i1 == -1) {
                        flag = false;
                        break;
                    }
                    left = j;
                    n++;
                }
            }
            if (j != 0 && j == queries[i].length()) {
                String substring = queries[i].substring(left, j);
                String s = patterns.get(n);
                int i1 = substring.indexOf(s);
                n++;
                if (i1 == -1 || n < len) {
                    flag = false;
                }
            } else if (j < queries[i].length()) {
                flag = false;
            }
            booleans.add(flag);
        }
        return booleans;
    }
}
